package com.woniu.p2p.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.p2p.entity.User;
import com.woniu.p2p.entity.UserScore;
import com.woniu.p2p.mapper.UserMapper;
import com.woniu.p2p.mapper.UserScoreMapper;
import com.woniu.p2p.service.P2PScoreService;
import com.woniu.p2p.vo.ScoreAndUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 86152
 * @create 2020/8/11
 * @since 1.0.0
 */
@Service
public class P2PScoreServiceImp implements P2PScoreService {
    @Autowired
    UserScoreMapper userScoreMapper;

    /*分页查询*/
    @Override
    public PageInfo<UserScore> findallscore(int userid, int start, int size) {
        PageHelper.startPage(start,size);
        List<UserScore> userScores= userScoreMapper.findByUserid(userid);
        PageInfo<UserScore> userScorePageInfo = new PageInfo<>(userScores);
        return userScorePageInfo;
    }

    @Autowired
    UserMapper userMapper;
    /*查询积分和用户信息*/
    @Override
    public ScoreAndUserVo findscoreanduserbyid(int userid, Integer scoreId) {
        User user = userMapper.selectByPrimaryKey(userid);
        UserScore userScore = userScoreMapper.selectByPrimaryKey(scoreId);
        ScoreAndUserVo scoreAndUserVo = new ScoreAndUserVo();
        scoreAndUserVo.setUser(user);
        scoreAndUserVo.setUserScore(userScore);
        return scoreAndUserVo;
    }
}
